/*
 * ! ******************************************************************************
 *
 * Created on 2022年10月1日
 *
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ******************************************************************************/
package org.pentaho.di.ui.util;

import cn.hutool.json.JSONUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.yzbdl.lanius.core.net.HttpUtil;
import org.yzbdl.lanius.core.database.dialog.DataOverrideHandler;
import org.pentaho.di.ui.core.dialog.ShowDbBrowserDialog;
import org.pentaho.di.ui.dbdto.DbdriverDto;

/**
 * @author tanpeng@yzbdl.ac.cn
 * @version 1.0
 * @date 2022-08-01 11:19
 */
public class BrowserUtils {
	private static final Class<?> PKG = BrowserUtils.class;

	/**
	 * 数据库连接页面 打开驱动列表页面
	 *
	 * @param shell
	 * @param dialogTitle
	 * @param url
	 * @param hadnler
	 * @author LC
	 * @return
	 */
	public static ShowDbBrowserDialog openDbDialog(Shell shell, String dialogTitle, String url,
												   DataOverrideHandler hadnler) {
		DbdriverDto dbdriverDto = new DbdriverDto();
		try {
			String string = HttpUtil.getString(url);
			dbdriverDto = JSONUtil.toBean(string, DbdriverDto.class);
		} catch (Exception e) {
			MessageBox mb = new MessageBox(shell, SWT.ERROR | SWT.ICON_INFORMATION);
			mb.setMessage("网络连接失败,请检查您的网络情况");
			mb.setText("提示");
			mb.open();
			;
		}
		ShowDbBrowserDialog dbDlg = new ShowDbBrowserDialog(shell, dialogTitle, url, hadnler);
		dbDlg.open(dbdriverDto);
		return dbDlg;
	}

//	/**
//	 * 打开支付二维码页面
//	 *
//	 * @param shell
//	 * @param dialogTitle
//	 * @param url
//	 * @return
//	 */
//	public static QrCodePaymentDialog openPayDialog(Shell shell, String dialogTitle, String url) {
//		QrCodePaymentDialog payDlg = new QrCodePaymentDialog(shell, dialogTitle, url);
//		payDlg.open();
//		return payDlg;
//	}
}
